1. Field of the Invention
This invention relates generally to software applications that use bytecode which is compiled into native code before being executed. More particularly, the invention relates to a system and method for compiling part of the bytecode for a software application into native code at the time when the software application is installed on a computer system.
2. Description of the Related Art
Software developers typically create the source code for software applications in a high-level programming language by writing textual program statements that specify the application's functionality. The source code may then be compiled into executable machine code that can be executed by a physical processor. This executable machine code is also referred to as native code because it is formatted so that it executes on a specific type of processor using that processor's instruction set. Thus, native code is typically not portable across different types of computing devices, e.g., devices that use different types of processors.
In some programming environments the source code is not compiled directly into native code, but is instead compiled into an intermediate form of code called bytecode. Bytecode is a binary representation of program instructions suitable for execution on a specific type of virtual machine. The virtual machine itself may be implemented in software and may be executed by the processor of the physical computing device. A software application that has been compiled into bytecode instructions may be executed on the virtual machine, e.g., by the virtual machine dynamically interpreting the bytecode instructions.
An alternative technique for executing bytecode is to use just-in-time (JIT) compilation to dynamically compile the bytecode into native code during execution of the software application. For example, each method in the bytecode may have a stub function which engages the JIT compiler and replaces itself (the stub) with the generated native code which is then executed. One benefit of JIT compilation is that only the bytecode that is actually called gets compiled into native code, thus avoiding the use of time and resources to compile bytecode that is not used. However, the downside is the time and expense of JIT-compiling the code at runtime. This can introduce a noticeable lag as new code is executed for the first time. Further, in some execution environments the native code produced from JIT compilation is not cached across invocations of the software application, and thus the same bytecode may have to be re-compiled if it is called again when the software application is re-launched.
Instead of JIT-compiling the bytecode at runtime, some or all of the bytecode may be compiled into native code when the software application is installed on the computer system, e.g., as part of the installation procedure. The resulting native code may be cached and executed when needed during subsequent executions of the software application, thus avoiding the lag resulting from JIT compilation. Also, if the bytecode is compiled at install time, the compiler can compile larger sections of bytecode at the same time than would typically be compiled during execution of the software application, which can allow the compiler to make better optimizations and produce more efficient native code. However, the downside to compiling the bytecode at install time is the time required to do so. For large software applications or for low-powered devices, the compilation can be very time consuming, which can mean that a user has to wait longer for the software application to be installed.